{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "823db596",
   "metadata": {},
   "source": [
    "---\n",
    "* 2023-10-18\n",
    "* 课程：python语言\n",
    "* week05（上课周）\n",
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eabc31e0",
   "metadata": {},
   "source": [
    "# 1.用户输入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6b41d0c1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：鹅bb\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'鹅bb'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "input(\"请输入你的账号：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "83f88273",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：鹅bb\n",
      "请输入你的密码：111\n"
     ]
    }
   ],
   "source": [
    "username = input(\"请输入你的账号：\")\n",
    "password = input(\"请输入你的密码：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "4c6d2735",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "鹅bb\n",
      "111\n"
     ]
    }
   ],
   "source": [
    "print(username)\n",
    "print(password)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "de909370",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的账号：鹅bb\n",
      "请输入你的密码：123456\n",
      "欢迎回家\n"
     ]
    }
   ],
   "source": [
    "# 假设 正确账号：鹅bb\n",
    "# # 假设 正确密码：12345\n",
    "\n",
    "# 登陆系统\n",
    "username = input(\"请输入你的账号：\")\n",
    "password = input(\"请输入你的密码：\")\n",
    "if username == \"鹅bb\" and password ==\"123456\":\n",
    "    print(\"欢迎回家\")\n",
    "else:\n",
    "    print(\"输入账户或密码错误\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "934049f2",
   "metadata": {},
   "source": [
    "* 笔记：\n",
    "> 1. == 代表判断左右两边是否相等（等于）；= 代表输出\n",
    "> 2. 所有符号要用英文符号\n",
    "> 3. 三个引号\"\"\"来进行多行注释"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6d4864e9",
   "metadata": {},
   "source": [
    "# 1.用户输出（格式化）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "02196ca5",
   "metadata": {},
   "source": [
    "# 2.1注释"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e6a65bbd",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 第一种：#表示单行注释\n",
    "# 第二种：三个引号\"\"\"将内容括起来进行多行注释"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4a358aa1",
   "metadata": {},
   "source": [
    "# 2.2格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a0c29a69",
   "metadata": {},
   "source": [
    "## 2.2.1 字符串的拼接实现格式化输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8436a348",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入你的姓名：查理苏未婚妻\n",
      "请输入你的年龄：19\n",
      "请输入你的职业：设计师\n",
      "请输入你的薪水：30000\n"
     ]
    }
   ],
   "source": [
    "# 指定格式的简历\n",
    "\n",
    "# 用户输入信息\n",
    "name = input(\"请输入你的姓名：\")\n",
    "age = input(\"请输入你的年龄：\")\n",
    "job = input(\"请输入你的职业：\")\n",
    "salary = input(\"请输入你的薪水：\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "cd8b9e87",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "---------INFO查理苏未婚妻---------\n",
      "姓名：查理苏未婚妻\n",
      "年龄：19\n",
      "工作：设计师\n",
      "薪水：30000\n"
     ]
    }
   ],
   "source": [
    "# 格式化输出内容\n",
    "\n",
    "INFO = \"\"\"---------INFO\"\"\" + name + \"\"\"---------\n",
    "姓名：\"\"\" + name + \"\"\"\n",
    "年龄：\"\"\" + age + \"\"\"\n",
    "工作：\"\"\" + job + \"\"\"\n",
    "薪水：\"\"\" + salary\n",
    "\n",
    "print(INFO)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40484fe0",
   "metadata": {},
   "source": [
    "* 笔记：上述代码使用的方法是“字符串的拼接”，用+实现"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "534380e9",
   "metadata": {},
   "source": [
    "## 2.2.2 字占位符实现格式化输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "4ccbff87",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "---------INFO 查理苏未婚妻 ---------\n",
      "姓名：查理苏未婚妻 \n",
      "年龄：19 \n",
      "工作：设计师\n",
      "薪水：30000 \n"
     ]
    }
   ],
   "source": [
    "INFO = \"\"\"---------INFO %s ---------\n",
    "姓名：%s \n",
    "年龄：%s \n",
    "工作：%s\n",
    "薪水：%s \"\"\"%(name,name,age,job,salary)\n",
    "\n",
    "print(INFO)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8ae336dc",
   "metadata": {},
   "source": [
    "* 笔记：占位符比较适合用于格式化字段较少的文本处理\n",
    "> 1. %s占位符是字符串\n",
    "> 2. %d占位符是数值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "28f8856b",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 2.2.3格式化方法：format()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "1c2640b6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "---------INFO 查理苏未婚妻 ---------\n",
      "姓名：查理苏未婚妻\n",
      "年龄：19\n",
      "工作：设计师\n",
      "薪水：30000 \n"
     ]
    }
   ],
   "source": [
    "# 格式化输出内容\n",
    "\n",
    "# N = name,J = job,S = salary, A = age\n",
    "INFO = \"\"\"---------INFO {N} ---------\n",
    "姓名：{N}\n",
    "年龄：{A}\n",
    "工作：{J}\n",
    "薪水：{S} \"\"\".format(N = name,J = job,S = salary, A = age)\n",
    "\n",
    "print(INFO)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3caf3d0",
   "metadata": {},
   "source": [
    "* 笔记：format方法可以解决占位符的两个痛点\n",
    "> 1. 不再考量位置顺序\n",
    "> 2. 解决重复字段出现问题，只需要赋值一次，如上述：N = name，只需写一次即可"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d73a44fd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
